package com.hspedu.seckill.model.context;

import com.hspedu.seckill.entity.User;

/**
 * @author: xujiabing
 * @date: 2025-02-16 17:04
 * @description: 用户线程上下文容器
 */
public class UserContext {

    // 每个线程都有自己的ThreadLocal,共享数据，保证线程安全
    private static final ThreadLocal<User>  userHolder = new ThreadLocal<>();

    public static void setUser(User user) {
        userHolder.set(user);
    }

    public static User getUser() {
        return userHolder.get();
    }
}
